import { Login } from './js/login/Login'
import {
  env
} from './.eslintrc';
function draw() {
    try {
      wx.onHide(() => {
        // 在这里执行当用户切换到后台时需要执行的逻辑
        console.log('用户切换到后台');
        console.log(wx.getStorageSync('currentSkin'))
        // 可以暂停游戏逻辑、保存游戏进度等操作
        wx.cloud.init({
          env: 'prod-8gf88ck5bb3ddd38'
        }) 
        wx.cloud.callContainer({
          "config": {
            "env": "prod-8gf88ck5bb3ddd38"
          },
          "path": "/apis/skin/updateUserSkins",
          "header": {
            'content-type': 'application/json',
            'AuthToken': wx.getStorageSync("AuthToken"),
            "X-WX-SERVICE": env.service
          },
          "data": {
            'currentSkin':wx.getStorageSync('currentSkin'),
          },
          "method": "POST",
          success: (res) => {
            console.log(res);
        },
        fail: console.warn,
        })
      });
    //   var task = wx.preDownloadSubpackage({
    //     packageType: "workers", 
    //     success(res) {
    //        console.log("load worker success", res)
    //        var worker = wx.createWorker("workers/request/index.js")   // 创建 worker。 如果 worker 分包没下载完就调 createWorker 的话将报错
    //     },
    //     fail(res) {
    //        console.log("load worker fail", res)
    //     }
    //  })
     
    //  task.onProgressUpdate(res => {
    //    console.log(res.progress) // 可通过 onProgressUpdate 接口监听下载进度
    //    console.log(res.totalBytesWritten)
    //    console.log(res.totalBytesExpectedToWrite)
    //  })

    const fs = wx.getFileSystemManager();
    try {
      console.log(wx.env.USER_DATA_PATH);
      const files = fs.readdirSync(`${wx.env.USER_DATA_PATH}/engine-cache`);
      console.log(files);
    } catch (error) {
      console.error("engine-cache 还没创建", error)
    }
     
        const login = new Login();
    } catch (error) {
        console.log(error)
        console.log(error.stack)
    }
}

draw();
